package main

import (
	"fmt"
	"math/big"

	"github.com/consensys/gnark-crypto/ecc/bn254/fr"
)

func checkFieldSize() {
	// BN254 scalar field 的模数
	modulus := fr.Modulus()
	fmt.Printf("BN254 scalar field modulus:\n%s\n\n", modulus.String())

	// 测试的 secret
	secretHex := "a173f2303c1c6ef28e04ba656704551e2332809fca8dd2a4094cd991f5ddbeeb"
	secretBig := new(big.Int)
	secretBig.SetString(secretHex, 16)
	fmt.Printf("Secret (原始):\n%s\n\n", secretBig.String())

	// 比较
	if secretBig.Cmp(modulus) >= 0 {
		fmt.Println("⚠️  Secret 超过了域的大小！会被自动模运算")
		reduced := new(big.Int).Mod(secretBig, modulus)
		fmt.Printf("Secret (缩减后):\n%s\n", reduced.String())
	} else {
		fmt.Println("✅ Secret 在域范围内")
	}
}
